<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h4 class="modal-title" id="myModalLabel" align="center">
                    拆分制作件清单
                </h4>
            </div>
            <div class="modal-body">
                <form id="partForm" class="form-horizontal" role="form">
                    <input type="hidden" id="id" name="id">
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">图号 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="drawNo">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">零件名称 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="drawName">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">零件数量 ：</label>
                        <div class="col-sm-9">
                            <input type="number" class="form-control" name="drawNum">
                        </div>
                    </div>
                    <!--<div class="form-group">-->
                        <!--<label class="col-sm-3 control-label no-padding-right">材质 ：</label>-->
                        <!--<div class="col-sm-9">-->
                            <!--<input type="text" class="form-control" name="quality">-->
                        <!--</div>-->
                    <!--</div>-->
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">零件类型</label>
                        <div class="col-sm-9">
                            <select id="query-makeType" class="form-control" name="makeType" >
                                <option value="加工件" selected>加工件</option>
                                <option value="装配件">装配件</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label no-padding-right">备注 ：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="remark">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" onclick="saveMaintain()" id="btn-maintain">
                    拆分
                </button>
                <button type="button" class="btn btn-primary" onclick="editMaintain()" id="btn-edit">
                    修改
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<section class="content-header">
    <h1>工艺清单明细</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="row"><br>
                    <div class="col-md-2">
                        <div class="form-group">
                            <label >项目编号：</label><label th:text="${craMakeSheet.proCode}"></label>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="form-group">
                            <label>项目名称：</label><label th:text="${craMakeSheet.proName}"></label>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <div class="form-group">
                            <label>项目数量：</label><label th:text="${craMakeSheet.proNum}"></label>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <div class="form-group">
                            <label>类型：</label><label th:text="${craMakeSheet.special}"></label>
                        </div>
                    </div>
                    <div class="col-md-2">
                        <div class="form-group">
                            <label>部分：</label><label th:text="${craMakeSheet.part}"></label>
                        </div>
                    </div>
                </div>
                <!--<div class="box-header">-->
                    <!--<table id="t1" class="t1">-->
                        <!--<thead style="display: table-header-group">-->
                        <!--<tr>-->
                            <!--<td colspan="14">-->
                                <!--<img th:src="@{/img/logo3.jpg}" width="40px" height="40px" style="margin-top: -30px">-->
                                <!--<div style="display: inline-block;margin-top: 5px;margin-left: 20px">-->
                                    <!--<span style="letter-spacing: 24px;display: block;line-height: 20px">&nbsp;辽宁忠旺机械设备制造有限公司</span>-->
                                    <!--<span style="display: block;font-size: 12px;line-height: 20px">Liaoning Zhongwang Machinery Equipment Manufacturing Co., Ltd</span>-->
                                <!--</div>-->
                            <!--</td>-->
                        <!--</tr>-->
                        <!--<tr>-->
                            <!--<td colspan="14" style="font-size: 16px;letter-spacing: 4px;">-->
                                <!--<span style="">制作件清单-拆分</span>-->
                            <!--</td>-->
                        <!--</tr>-->
                        <!--<tr>-->
                            <!--<td colspan="2" style="width: 8%;">项目编号</td>-->
                            <!--<td style="width: 10%;">-->
                                <!--[[${craMakeSheet.proCode}]]-->
                            <!--</td>-->
                            <!--<td style="width: 8%">项目名称</td>-->
                            <!--<td colspan="3" style="width: 30%">-->
                                <!--[[${craMakeSheet.proName}]]-->
                            <!--</td>-->
                            <!--<td style="width: 8%">项目数量</td>-->
                            <!--<td style="width: 6%">-->
                                <!--[[${craMakeSheet.proNum}]]-->
                            <!--</td>-->
                            <!--<td style="width: 6%">类型</td>-->
                            <!--<td style="width: 9%">-->
                                <!--[[${craMakeSheet.special}]]-->
                            <!--</td>-->
                            <!--<td style="width: 6%">部分</td>-->
                            <!--<td style="width: 9%">-->
                                <!--[[${craMakeSheet.part}]]-->
                            <!--</td>-->
                        <!--</tr>-->

                        <!--</thead>-->

                    <!--</table>-->

                <!--</div>-->
                <div class="box-body">
                    <form id="queryForm" onsubmit="return false;">
                        <input type="hidden" id="makeSheetId" name="sheetId" th:value="${craMakeSheet.id}">
                        <!--<input type="hidden" id="makeSheetType" name="sheetType"-->
                        <!--th:value="${serviceTaskModel.sheetType}">-->
                    </form>
                    <!--<button type="button" class="btn btn-success" id="btn-receive"-->
                    <!--onclick="selected()"  v-if="form.status === 1">-->
                    <!--<span class="Bold">接收</span>-->
                    <!--</button>-->
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<!--<input type="hidden" id="sheetType" th:value="${serviceTaskModel.sheetType}">-->
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table, columns,
        sheetId = +$("#sheetId").val(),
        sheetType = +$("#sheetType").val();

    $(function () {

        /** 加载列表 */
        table = js.table.init({
            url: ctx + "craft/maintain/detail/list",
            showExport: false,
            uniqueId: 'id',
            columns: [
                {

                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "图号", field: 'drawNo'},
                {title: "零件名称", field: 'drawName'},
                {title: "零件数量", field: 'drawNum'},
                {title: "制作件类型", field: 'makeType'},
                // {title: "材质", field: 'quality'},
                // {
                //     title: "附件", field: 'url',
                //     formatter: function (value) {
                //         if (value) {
                //             return '<a target="_blank" href="' + value + '">下载</a>'
                //         }
                //         return '';
                //     }
                // },
                {title: "备注", field: 'remark'},
                {title: "创建人/接收人", field: 'creatName'},
                {title: "创建时间", field: 'creatTime'},
                {
                    title: "操作",
                    formatter: function (value, row) {

                        let actions = [];
                        if (row.detailPid == null) {
                            actions.push('<a class="btn btn-warning btn-xs many-view" shiro:hasPermission="tec:proDirediting:edit" href="javascript:void(0)" onclick="openReleaseModal(&quot;' + row.id + '&quot;,&quot;' + 2 + '&quot;)"> 拆分</a> ');
                        } else {
                            actions.push('<a class="btn btn-danger btn-xs" shiro:hasPermission="tec:proDirediting:del" href="javascript:void(0)" onclick="del(' + row.id + ')"> 删除</a>');
                            actions.push('<a class="btn btn-warning btn-xs many-view" shiro:hasPermission="tec:proDirediting:edit" href="javascript:void(0)" onclick="openReleaseModal(&quot;' + row.id + '&quot;,&quot;' + 1 + '&quot;)"> 修改</a> ');
                        }
                       if(row.outsourcing==1){

                           actions.push('<a class="btn btn-warning btn-xs" shiro:hasPermission="tec:proDirediting:edit" href="javascript:void(0)" onclick="reOutsourcing(' + row.id + ')"> 取消</a>');

                       }else {
                           actions.push('<a class="btn btn-primary btn-xs" shiro:hasPermission="tec:proDirediting:edit" href="javascript:void(0)" onclick="outsourcing(' + row.id + ')"> 外协</a>');
                       }
                        return actions.join('');
                    }
                }
            ]
        });
    });

    /** 删除数据 */
    function del(id) {
        js.modal.confirm("确认删除吗？", function () {
            js.post({
                url: ctx + "craft/maintain/detail/del",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.alert("工艺员已经创建工艺卡，请联系工艺员删除工艺卡后再删除此单据！！");
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }

    /** 整体外协 */
    function outsourcing(id) {
        js.modal.confirm("确认整体外协吗？", function () {
            js.post({
                url: ctx + "craft/maintain/detail/outsourcing",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.alert("工艺员已经创建工艺卡，请联系工艺员删除工艺卡后再整体外协！！");
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }
    /** 取消整体外协 */
    function reOutsourcing(id) {
        js.modal.confirm("确认取消整体外协吗？", function () {
            js.post({
                url: ctx + "craft/maintain/detail/reOutsourcing",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.alert("工艺员已经创建工艺卡，请联系工艺员删除工艺卡后再整体外协！！");
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }
    /** * 修改用户模态框 */
    function openReleaseModal(id,takeType) {
        var rowData = $('#bootstrap-table').bootstrapTable('getRowByUniqueId', id);//行的数据
        $("#partForm").fillSpan(rowData);
        $("#partForm").fillData(rowData);
        if(takeType==2){
            $("#btn-maintain").show();
            $("#btn-edit").hide();
        }else {
            $("#btn-maintain").hide();
            $("#btn-edit").show();
        }
        js.modal.open("myModal");
    }

    function saveMaintain() {
        var url = ctx + "craft/maintain/detail/maintain";
        js.validSubmit({
            formId: "partForm",
            url: url,
            data: new FormData($("#partForm")[0]),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    js.modal.hide("myModal");
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });

    }
    function editMaintain() {
        var url = ctx + "craft/maintain/detail/editMaintain";
        js.validSubmit({
            formId: "partForm",
            url: url,
            data: new FormData($("#partForm")[0]),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    js.modal.hide("myModal");
                } else {
                    js.modal.alert("工艺员已经创建工艺卡，请联系工艺员删除工艺卡后再修改此单据！！");
                    js.modal.warning(result.msg);
                }
            }
        });
    }

    $("#bootstrap-table").on('click', ".many-view", function () {
        $(this).css({'background-color' : 'green', 'font-weight' : 'bolder'});
    });
</script>
</body>
</html>
